import java.util.Random;
import java.util.Scanner;

/**
 * @Author YuanYuan
 * @Date 2022/4/23
 * @Time 20:16
 */
public class TestDemo {
    public static int MAX = 100;
    public static void menu(){
        System.out.println("******* 猜数字游戏 ********");
        System.out.println("******* 1.开始游戏 ********");
        System.out.println("******* 0.退出游戏 ********");
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();
        do{
            menu();
            int input = scanner.nextInt();
            if(0 == input){
                break;
            }
            int toGuess = random.nextInt(100);
            System.out.println("请输入一个数字：");
            while(scanner.hasNextInt()) {
                int num = scanner.nextInt();
                if((num<1)||(num>100)){
                    System.out.println("输入错误！");
                    break;
                }
                if(toGuess > num) {
                    System.out.println("猜小了，重新输入：");
                }else if(toGuess < num) {
                    System.out.println("猜大了，重新输入：");
                }else {
                    System.out.println("恭喜你！猜对啦！");
                    break;
                }
            }
        }while(true);

    }
}
